/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package amanda_gabriel_isabella_lucivania_monica.View;

import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Aluno;
import amanda_gabriel_isabella_lucivania_monica.Model.Dao.DaoBaseImpl;

/**
 *
 * @author lucy
 */
public class EditarAlunoIG extends javax.swing.JFrame {

    /**
     * Creates new form EditarAlunoIG
     */
    private DaoBaseImpl daoBaseImpl;

    public EditarAlunoIG(DaoBaseImpl daoBaseImpl) {
        initComponents();
        this.daoBaseImpl = daoBaseImpl;
        jTNome.setEditable(false);
        jTCpf.setEditable(false);
        jBSalvar.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jBEditar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();
        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("amanda_gabriel_isabella_lucivania_monicaPU").createEntityManager();
        alunoQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Aluno a");
        alunoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : alunoQuery.getResultList();
        jDSucess = new javax.swing.JDialog();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jBSim = new javax.swing.JButton();
        jBNao = new javax.swing.JButton();
        jPEditarAluno = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jLListaAluno = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPDadosAluno = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTNome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTCpf = new javax.swing.JTextField();
        jBSalvar = new javax.swing.JButton();

        jBEditar.setText("Editar");
        jBEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditarActionPerformed(evt);
            }
        });

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jDSucess.setMinimumSize(new java.awt.Dimension(400, 176));

        jLabel6.setText("Disciplina cadastrada com sucesso!");

        jLabel7.setText("Deseja realizar outro cadastro?");

        jBSim.setText("Sim");
        jBSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSimActionPerformed(evt);
            }
        });

        jBNao.setText("Não");
        jBNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDSucessLayout = new javax.swing.GroupLayout(jDSucess.getContentPane());
        jDSucess.getContentPane().setLayout(jDSucessLayout);
        jDSucessLayout.setHorizontalGroup(
            jDSucessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessLayout.createSequentialGroup()
                .addGroup(jDSucessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDSucessLayout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addGroup(jDSucessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6)))
                    .addGroup(jDSucessLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jDSucessLayout.setVerticalGroup(
            jDSucessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jDSucessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBSim)
                    .addComponent(jBNao))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Editar Aluno");
        setMinimumSize(new java.awt.Dimension(400, 175));

        jPEditarAluno.setBorder(javax.swing.BorderFactory.createTitledBorder("Por favor, selecione o aluno que deseja editar:"));

        org.jdesktop.swingbinding.JListBinding jListBinding = org.jdesktop.swingbinding.SwingBindings.createJListBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, alunoList, jLListaAluno);
        bindingGroup.addBinding(jListBinding);

        jScrollPane2.setViewportView(jLListaAluno);

        javax.swing.GroupLayout jPEditarAlunoLayout = new javax.swing.GroupLayout(jPEditarAluno);
        jPEditarAluno.setLayout(jPEditarAlunoLayout);
        jPEditarAlunoLayout.setHorizontalGroup(
            jPEditarAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPEditarAlunoLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 463, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPEditarAlunoLayout.setVerticalGroup(
            jPEditarAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPEditarAlunoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setText("Editar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPDadosAluno.setBorder(javax.swing.BorderFactory.createTitledBorder("Informe os novos dados para o aluno:"));

        jLabel1.setText("Nome:");

        jTNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNomeActionPerformed(evt);
            }
        });

        jLabel2.setText("CPF:");

        javax.swing.GroupLayout jPDadosAlunoLayout = new javax.swing.GroupLayout(jPDadosAluno);
        jPDadosAluno.setLayout(jPDadosAlunoLayout);
        jPDadosAlunoLayout.setHorizontalGroup(
            jPDadosAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPDadosAlunoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPDadosAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPDadosAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTNome)
                    .addComponent(jTCpf, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPDadosAlunoLayout.setVerticalGroup(
            jPDadosAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPDadosAlunoLayout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(jPDadosAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPDadosAlunoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jBSalvar.setText("Salvar");
        jBSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPDadosAluno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPEditarAluno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 339, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton2)
                                .addGap(28, 28, 28))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jBSalvar)
                                .addContainerGap())))))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPEditarAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(27, 27, 27)
                .addComponent(jPDadosAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBSalvar)
                .addContainerGap(93, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2});

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditarActionPerformed
      
    }//GEN-LAST:event_jBEditarActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jTNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTNomeActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalvarActionPerformed
        Aluno aluno = (Aluno) jLListaAluno.getSelectedValue();
        aluno.setCpf(jTCpf.getText());
        aluno.setNome(jTNome.getText());
        daoBaseImpl.update(aluno);
        jDSucess.setVisible(true);
    }//GEN-LAST:event_jBSalvarActionPerformed

    private void jBSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSimActionPerformed
        jDSucess.dispose();
        jTNome.setEditable(false);
        jTCpf.setEditable(false);
        jBSalvar.setEnabled(false);
        jDSucess.dispose();
    }//GEN-LAST:event_jBSimActionPerformed

    private void jBNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNaoActionPerformed
        setVisible(false);
        jDSucess.dispose();
    }//GEN-LAST:event_jBNaoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Aluno aluno = (Aluno) jLListaAluno.getSelectedValue();
       
       jTNome.setEditable(true);
       jTCpf.setEditable(true);
       jBSalvar.setEnabled(true);
       
       
       jTNome.setText(aluno.getNome());
       jTCpf.setText(aluno.getCpf());
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Aluno> alunoList;
    private javax.persistence.Query alunoQuery;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBEditar;
    private javax.swing.JButton jBNao;
    private javax.swing.JButton jBSalvar;
    private javax.swing.JButton jBSim;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JDialog jDSucess;
    private javax.swing.JList jLListaAluno;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPDadosAluno;
    private javax.swing.JPanel jPEditarAluno;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTCpf;
    private javax.swing.JTextField jTNome;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
